package cst.neu.yuejian_31.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.bean.RefundBean;
import cst.neu.yuejian_31.iface.RefundListener;
import cst.neu.yuejian_31.model.RefundModel;
import cst.neu.yuejian_31.Common.Constant;

public class OrderDetailActivity extends BaseActivity implements View.OnClickListener,RefundListener {
    private TextView orderName,orderNum,orderTotal,orderTime,orderIntro,orderPrice;
    private ImageView orderPic,orderState;
    private Button btn_rMoney;
    private ImageView btn_return;
    private String state,cpic,tpic,apic,orderId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        initView();
        initDate();
        initEvent();
    }

    private void initEvent() {
        btn_return.setOnClickListener(this);
        btn_rMoney.setOnClickListener(this);
    }

    private void initDate() {
        Intent intent=getIntent();
        orderId=intent.getStringExtra("order_id");
        orderName.setText(intent.getStringExtra("order_name"));
        orderNum.setText(intent.getStringExtra("order_num"));
        orderTotal.setText(intent.getStringExtra("order_total"));
        orderTime.setText(intent.getStringExtra("order_time"));
        orderIntro.setText(intent.getStringExtra("order_intro"));
        orderPrice.setText(intent.getStringExtra("order_money"));
        cpic=intent.getStringExtra("order_cpic");
        tpic=intent.getStringExtra("order_tpic");
        apic=intent.getStringExtra("order_apic");
        if(cpic!=null){
            Picasso.with(OrderDetailActivity.this).load(Constant.CLASS_URL+cpic).into(orderPic);
        }
        if(tpic!=null){
            Picasso.with(OrderDetailActivity.this).load(Constant.TRAIN_URL+tpic).into(orderPic);
        }
        if(apic!=null){
            Picasso.with(OrderDetailActivity.this).load(Constant.ACTIVITY_URL+apic).into(orderPic);
        }
        state=intent.getStringExtra("order_state");
        if (state.equals("1")){
            orderState.setImageResource(R.drawable.ic_finish);
        }else {
            orderState.setImageResource(R.drawable.ic_unfinished);
        }

    }

    private void initView() {
        orderName= (TextView) findViewById(R.id.textView_orderdetail_name);
        orderNum= (TextView) findViewById(R.id.textView_orderdetail_num);
        orderTotal= (TextView) findViewById(R.id.textView_orderdetail_total);
        orderTime= (TextView) findViewById(R.id.textView_orderdetail_time);
        orderIntro= (TextView) findViewById(R.id.textView_orderdetail_intro);
        orderPrice= (TextView) findViewById(R.id.textView_orderdetail_money);
        orderPic= (ImageView) findViewById(R.id.imageView_orderdetail_pic);
        orderState= (ImageView) findViewById(R.id.imageView_orderdetail_state);
        btn_rMoney= (Button) findViewById(R.id.button_rmoney);
        btn_return= (ImageView) findViewById(R.id.imageView_ov_return);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button_rmoney:
                refund();
                break;
            case R.id.imageView_ov_return:
                finish();
                break;
        }

    }

    private void refund() {
        RefundModel refundmodel=new RefundModel();
        refundmodel.reFund(orderId,this);

    }

    @Override
    public void onSuccess(RefundBean refundBean) {
        Toast.makeText(this, "退款申请成功", Toast.LENGTH_SHORT).show();
        
    }

    @Override
    public void onFail(String msg) {

    }
}
